//
//  SelectLayout.m
//  Unity-iPhone
//
//  Created by Karl on 2017/3/30.
//
//

#import "SelectLayout.h"

@implementation SelectLayout

- (instancetype)init{
    self = [super init];
    if (self) {
        self.selectedIndexPath = nil;
    }
    return self;
}

-(void)prepareLayout
{
    [super prepareLayout];
    [self setupLayout];
}
- (void)setupLayout
{
    CGFloat scale = 1.0;
    if (isPad) {
        scale = SizeScaleX;
    }else{
        scale = SizeScaleY;
    }
    
    self.itemSize = CGSizeMake(60 *scale,60 *scale);
    self.minimumInteritemSpacing =  30.0*scale;
    self.minimumLineSpacing = 30.0 *scale;
    self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSArray *attributes = [super layoutAttributesForElementsInRect:rect];

    if (self.selectedIndexPath == nil) {
        return attributes;
    }
    
    for (UICollectionViewLayoutAttributes *attrs in attributes) {
       
        CGFloat scale = 1.0;
        
        if (attrs.indexPath.section == _selectedIndexPath.section && attrs.indexPath.item == _selectedIndexPath.item) {
            scale = 1.25;
        }
        
        attrs.transform = CGAffineTransformMakeScale(scale, scale);
    }
    
    return  attributes;
}

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
    
    return YES;
}


@end
